#!/usr/bin/env python3
'''ssh 权限自动化开通'''
__author__="dk"

from flask import Flask
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api

class APP(Flask):
    def __init__(self,config):
        Flask.__init__(self,__name__)
        self.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://%s:%s@%s:%s/%s' % (config.mysql["user"],
                                                                             config.mysql["password"],
                                                                             config.mysql["host"], config.mysql["port"],
                                                                             config.mysql["database"])
        self.config['SQLALCHEMY_ECHO'] = False
        self.config['SQLALCHEMY_POOL_SIZE'] = int(config.mysql["db-connection-pool"])
        self.config['DEBUG'] = False
        self.db = SQLAlchemy(self, session_options={'autocommit': True})

    def get_db(self):
        '''连接数据库'''
        return self.db

    def get_api(self):
        '''调用借口函数'''
        return Api(self,catch_all_404s=True)